let express = require('express');
let bodyParser = require('body-parser');
let app = express();
 
app.use(bodyParser.json());

//解决跨域问题
app.all('*', function(req, res, next) {
  res.header('Access-Control-Allow-Origin', '*')
  res.header('Access-Control-Allow-Headers', '*')
  res.header('Access-Control-Allow-Methods', 'PUT,POST,GET,DELETE,OPTIONS')
  res.header('Content-Type', 'application/json;charset=utf-8')
  next()
})

app.get('/address',(req,res)=>{
   res.send( [{
            date: '2016-05-02',
            name: '王小虎',
            address: '上海市普陀区金沙江路 1518 弄=='
          }, {
            date: '2016-05-04',
            name: '王小虎',
            address: '上海市普陀区金沙江路 1517 弄=='
          }, {
            date: '2016-05-01',
            name: '王小虎',
            address: '上海市普陀区金沙江路 1519 弄=='
          }, {
            date: '2016-05-03',
            name: '王小虎',
            address: '上海市普陀区金沙江路 1516 弄=='
          }])
})

app.post("/add/goods",(req,res)=>{
  console.log(req.body);
  res.send({
    msg: "success"
  })
})

app.listen(8080,()=>{
   console.log("服务器启动：","http://localhost:8080")
})
